package algorithmTopics.array;


import java.util.Arrays;

public class test11 {
    public static void main(String[] args) {
        test11 test11 = new test11();
        int[][] matrix = {
                {5, 1, 9, 11},
                {2, 4, 8, 10},
                {13, 3, 6, 7},
                {15, 14, 12, 16}
        };
        test11.rotate(matrix);
        System.out.println(Arrays.toString(matrix));
    }

    public void rotate(int[][] matrix) {
        int temp = 0;
        int length = matrix.length;
        //直接一圈一圈旋转即可
        //矩阵圈数等于长度/2
        for (int i = 0; i < length / 2; i++) {
            for (int j = i; j < length - 1 - i; j++) {
                //存当前第一个，一行每个都选择四次就可以了
                temp = matrix[i][j];
                //左下角一个移动到左上角
                matrix[i][j] = matrix[length - j - 1][i];
                //右下角移动到左下角
                matrix[length - j - 1][i] = matrix[length - i - 1][length - j - 1];
                //右上角--->右下角
                matrix[length - i - 1][length - j - 1] = matrix[j][length - i - 1];
                matrix[j][length - i - 1] =temp;
            }
        }
    }

}
